package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.newyearbag.NewYearBagConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.newyearbag.NewYearBagMgr;
import com.yanqu.road.utils.date.DateHelper;

import java.util.ArrayList;
import java.util.List;

public class NewYearBagRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        NewYearBagConfig config = NewYearBagMgr.getNewYearBagConfig();
        if (config != null) {
            ActivityInfo activityInfo = config.getActivityInfo();

            // 红包回收换元宝
            long recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
            List<String> paramList = new ArrayList<>();
            paramList.add(String.valueOf(config.getHongBaoId()));
            paramList.add(String.valueOf(GameConfig.GAME_MONEY_INGOTS));
            paramList.add("1");
            paramList.add(activityInfo.getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(config.getHongBaoId(), activityType, 1, recycleTime, paramList);

            // 清空现金道具
            long clearXianJinTime = activityInfo.getEndShowTime() * 1000L + DateHelper.DAY_MILLIONS * 15;
            ActivityItemRecycleMgr.addRecycleItemData(config.getXianJinId(), activityType, 2, clearXianJinTime, new ArrayList<>());

        }
    }

    @Override
    public boolean isActivityRunning() {
        return ActivityMgr.activityInTime(NewYearBagMgr.getActivityInfo());
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.NewYearBag.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 1) {
            item2Score(userId, data);
        } else if (data.getRecycleType() == 2) {
            UserBagItem userBagItem = getUserBagItem(userId, data.getItemId());
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }

}
